package cn.bjxy.shishaolong.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * @Author 时少龙
 * @Date 2019-04-21 15:11
 * @Version 1.0
 */
@Component
@PropertySource("classpath:config/system-config.properties")
public class FileUtil {

    @Value("${fastDFS.server}")
    private String fastDfsServer;

    public static final String HTTP = "http";
    public static final String HTTPS = "https";

    /**
     * 将文件路径生成url
     *
     * @param protal
     * @param path
     * @return
     */
    public String generatorUrl(String protal, String path) {
        StringBuffer sb = new StringBuffer();
        sb.append(protal).append("://").append(fastDfsServer).append("/").append(path);
        return sb.toString();
    }


    /**
     * 获取 fastDFS文件服务器 地址HTTP_URL
     * @return
     */
    public String getFastDfsFileUrl(){
        return fastDfsServer+"/";
    }

    /**
     * 获取 fastDFS文件服务器 地址HTTP_URL
     * @return
     */
    public String getFastDfsFileHttpUrl(){
        return generatorUrl(HTTP, "");
    }

    /**
     * 获取 fastDFS文件服务器 地址HTTPS_URL
     * @return
     */
    public String getFastDfsFileHttpsUrl(){
        return generatorUrl(HTTPS, "");
    }

}
